package common

type ScoreCalculator interface {
	Calculate(giftValue uint64) uint64
	Settlement(giftValue uint64) uint64
}

var (
	// scoreStrategyRegistry 注册每个游戏的积分策略，key 为游戏名
	ScoreStrategyRegistry = map[string]ScoreCalculator{}
)

// RegisterScoreStrategy 注册某个游戏的积分计算策略
func RegisterScoreStrategy(gameName string, calc ScoreCalculator) {
	ScoreStrategyRegistry[gameName] = calc
}

// HasScoreStrategy 判断某个游戏是否已注册策略
func HasScoreStrategy(gameName string) bool {
	_, ok := ScoreStrategyRegistry[gameName]
	return ok
}

// 默认策略实现（默认 1 礼物价值 = 100 积分）
type DefaultGameScore struct{}

func (d *DefaultGameScore) Calculate(value uint64) uint64 {
	return value * 100
}
func (d *DefaultGameScore) Settlement(value uint64) uint64 {
	// 默认积分计算
	// 积分池10% 增加给主播
	return value / 10
}
